﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lilium.Web.Mvc;
using Lilium.Collections;
using System.Web.Mvc;
using System.Web.Routing;

namespace Lilium.Web.Mvc.Context
{
	public class ActionContextService: ControllerService, IActionContextService
	{
		public ActionContextService(ControllerBase controller)
			: base(controller)
		{
		}

		#region IActionContextService Members

		public RouteValueDictionary GetCombinedRouteValues()
		{
			var routeValues = new RouteValueDictionary(RouteValues);
			routeValues.Merge(ActionParameters);
			return routeValues;
		}

		public void SetActionContext(ActionExecutingContext filterContext)
		{
			if (filterContext == null) throw new ArgumentNullException("filterContext");

			m_RouteValues = filterContext.RouteData.Values;
			m_ActionParameters = filterContext.ActionParameters;
		}

		#endregion

		#region public IDictionary<string, object> ActionParameters

		private IDictionary<string, object> m_ActionParameters;

		public IDictionary<string, object> ActionParameters
		{
			get
			{
				return m_ActionParameters;
			}
		}

		#endregion

		#region private RouteValueDictionary RouteValues

		private RouteValueDictionary m_RouteValues;

		private RouteValueDictionary RouteValues
		{
			get
			{
				return m_RouteValues;
			}
		}

		#endregion
	}
}
